package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import com.ruoyi.system.domain.Officialstudent;
import com.ruoyi.system.domain.SysListenStudent;
import com.ruoyi.system.service.IOfficialstudentService;
import com.ruoyi.system.service.SysListenStudentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Forecastname;
import com.ruoyi.system.service.IForecastnameService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预报名管理Controller
 * 
 * @author ruoyi
 * @date 2021-11-08
 */
@Controller
@RequestMapping("/system/Forecastname")
public class ForecastnameController extends BaseController
{
    private String prefix = "system/Forecastname";
    @Autowired
    private SysListenStudentService service;
    @Autowired
    private IForecastnameService forecastnameService;
    @Autowired
    private IOfficialstudentService iOfficialstudentService;
    @RequiresPermissions("system:Forecastname:view")
    @GetMapping()
    public String Forecastname()
    {
        return prefix + "/Forecastname";
    }

    /**
     * 查询预报名管理列表
     */
    @RequiresPermissions("system:Forecastname:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Forecastname forecastname)
    {
        startPage();
        List<Forecastname> list = forecastnameService.selectForecastnameList(forecastname);
        return getDataTable(list);
    }

    /**
     * 导出预报名管理列表
     */
    @RequiresPermissions("system:Forecastname:export")
    @Log(title = "预报名管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Forecastname forecastname)
    {
        List<Forecastname> list = forecastnameService.selectForecastnameList(forecastname);
        ExcelUtil<Forecastname> util = new ExcelUtil<Forecastname>(Forecastname.class);
        return util.exportExcel(list, "预报名管理数据");
    }

    /**
     * 新增预报名管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存预报名管理
     */
    @RequiresPermissions("system:Forecastname:add")
    @Log(title = "预报名管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Forecastname forecastname)
    {
        System.out.println(forecastname);
        return toAjax(forecastnameService.insertForecastname(forecastname));
    }

    /**
     * 修改预报名管理
     */
    @GetMapping("/edit/{stuId}")
    public String edit(@PathVariable("stuId") String stuId, ModelMap mmap)
    {
        Forecastname forecastname = forecastnameService.selectForecastnameByStuId(stuId);
        mmap.put("forecastname", forecastname);
        return prefix + "/edit";
    }

    /**
     * 修改保存预报名管理
     */
    @RequiresPermissions("system:Forecastname:edit")
    @Log(title = "预报名管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Forecastname forecastname)
    {
        return toAjax(forecastnameService.updateForecastname(forecastname));
    }

    /**
     * 删除预报名管理
     */
//    @RequiresPermissions("system:Forecastname:remove")
//    @Log(title = "预报名管理", businessType = BusinessType.DELETE)
//    @PostMapping( "/remove")
//    @ResponseBody
//    public AjaxResult remove(String ids)
//    {
//        return toAjax(forecastnameService.deleteForecastnameByStuIds(ids));
//    }
    // 修改状态试听1
   @PostMapping("/Status")
    @ResponseBody
    public AjaxResult status(SysListenStudent sysListenStudent,String listenSexx)
    {
        if("男".equals(listenSexx)){
            sysListenStudent.setListenSex(0);
        }else {
            sysListenStudent.setListenSex(1);
        }
        sysListenStudent.setListenCreatTime(new Date());

        sysListenStudent.setListenStatus(1);
        int i = service.insertAll(sysListenStudent);
        System.out.println(sysListenStudent);
        return toAjax(forecastnameService.updateStace1(sysListenStudent.getListenId().toString()));
    }
    // 修改状态试听2
    @PostMapping("/Statuss")
    @ResponseBody
    public AjaxResult statuss(Officialstudent ids)
    {
        Date date = new Date();
        String s = date.toString();
        ids.setRegularTime(s);
        ids.setRegularStatus("3");
        System.out.println(ids);
        iOfficialstudentService.insertOfficialstudent(ids);
        return toAjax(forecastnameService.updateStace2(ids.getRegularId()));
    }
//    //
//    @PostMapping("/Statuss")
//    @ResponseBody
//    public office statuss(String ids)
//    {
//        System.out.println(ids);
//        return toAjax(forecastnameService.updateStace2(ids));
//    }
}
